package com.google.developers.tv.gdl;

import com.google.android.youtube.api.YouTube;
import com.google.android.youtube.api.YouTubePlayer;
import com.google.android.youtube.api.YouTubePlayerFragment;
import com.google.android.youtube.api.YouTubePlayerView;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class DashboardActivity extends Activity {

//  @Override
//  public void onCreate(Bundle savedInstanceState) {
//    super.onCreate(savedInstanceState);
//    YouTube.initialize(this, DeveloperKey.DEVELOPER_KEY);
//    setContentView(R.layout.activity_dashboard);
//
//    YouTubePlayer youTubePlayer =
//        (YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.youtubeView);
//    if (savedInstanceState == null) {
//      youTubePlayer.loadVideo("nCgQDjiotG0");
//    }
//  }
  
  public YouTubePlayerView mYouTubeView = null;
  private boolean mFullScreen = false;
  private static final String TAG = "GDL Dashboard Activity";
  String[] listItems = {
      "Live",
      "Coming Up",
      "Recently aired",
      "Channels",
      //"Favorites", // TODO
      //"History",   // TODO
      //"Calendar",  // TODO
      "Options",
      };

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    YouTube.initialize(this,
        "AI39si5y4xXvvOb86UiDUgQm5yUJ6bx36JW4ZbE88jOyT9qOxCi2cH2pJTp9icT6D7DfeZiewJMON7ooae_WZtFLvW86eIrHJg");
    
    // Remove title bar
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    // Remove notification bar
    this.getWindow().setFlags(
        WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_dashboard);

    ListView menuList = (ListView) findViewById(R.id.menuList);
    menuList.setAdapter(
        new ArrayAdapter(menuList.getContext(), android.R.layout.simple_list_item_1, listItems));

    YouTubePlayer youTubePlayer =
        (YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.youtubeView);
    if (savedInstanceState == null) {
//      youTubePlayer.loadVideo("nCgQDjiotG0"); //9P50Z4VdddA
      youTubePlayer.loadVideo("9P50Z4VdddA");
    }

//    // We register the YouTube Player
//    mYouTubeView = (YouTubePlayerView) findViewById(R.id.youtubeView);
//    registerPlayerView(mYouTubeView);
//    mYouTubeView.enableCustomFullscreen(this); // #2 - Custom Full Screen
//    //mYouTubeView.setOnPlaybackEventsListener(this); // #3 - Playback events
//    mYouTubeView.setPlaybackEventListener(this);
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_dashboard, menu);
    return true;
  }
}
